home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
mplus_1.exe
/
MENUDEMO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-12-01
|
17KB
|
611 lines
/*--------------------------------------------------------------
* File: MENUDEMO.C
* Description: Demo the MPLUS Menu System.
*
* This demo developed for the MPLUS Graphic Interface Library.
*-------------------------------------------------------------*/
#include <stdio.h>
#include <graph.h>
#include <math.h>
#include "gplus.h"
#include "gscreen.h"
#include "mouser.h"
#include "mpmenu.h"
#define ESC 0x011B /* scan & ascii code for ESC key */
#define CTRL_M 0x320D /* hot key for memory */
int dummy(), exitfun();
int memfun();
int mres(), hres(), eres(), vres();
int info(), demo1(), demo2();
void sinplot();
void setaxis();
/*--------------------------------------------------------------
* Initialize menu structures.
*-------------------------------------------------------------*/
/* Titles for pull down menus. Main menu bar done last because
* of backward referencing.
*/
struct MENU_ITEM mi_file[] =
{
"Save", dummy, NULL, 0, 0,1,0, /* dummy entries marked */
"Load", dummy, NULL, 0, 0,1,0, /* with grey out */
"DOS", dummy, NULL, 0, 0,1,0,
"Exit to System", exitfun, NULL, 0, 0,0,0,
NULL, NULL, NULL, 0,0,0,
};
struct MENU_ITEM mi_system[] =
{
"Memory\tCTRL+M", memfun, NULL, CTRL_M, 0,0,0,
NULL, NULL, NULL, 0, 0,0,0,
};
struct MENU_ITEM mi_videomode[] =
{
"Medium Res 4 Color", mres, NULL, 0, 0,0,0,
"Hi Res Black & White", hres, NULL, 0, 0,0,0,
"EGA", eres, NULL, 0, 0,0,0,
"VGA", vres, NULL, 0, 0,0,0,
NULL, NULL, NULL, 0, 0,0,0,
};
struct MENU_ITEM mi_help[] =
{
"Info", info, NULL, 0, 0,0,0,
"Demo 1", demo1, NULL, 0, 0,0,0,
"Demo 2", demo2, NULL, 0, 0,0,0,
NULL, NULL, NULL, 0, 0,0,0,
};
/* Titles for main menu goes last because of backward
* referencing of pulldown menu structures.
*/
struct MENU_ITEM menubar[] =
{
"File", NULL, mi_file, 0, 1, 0, 0,
"System", NULL, mi_system, 0, 1, 0, 0,
"Video", NULL, mi_videomode, 0, 1, 0, 0,
"Help", NULL, mi_help, 0, 1, 0, 0,
"Exit", exitfun, NULL, 0, 0, 0, 0,
NULL, NULL, NULL, 0,0,0,
};
struct MENU_INFO menu_info =
{
ESC, exitfun, /* exit key & function */
BLACK, CYAN, RED, GREY, /* attr of bar menu */
_GBORDER, BLUE, WHITE, BLUE, GREY, /* attr of pull down windows */
};
extern struct videoconfig _videoconfig;
/*--------------------------------------------------------------
* Function: main
* Description: demos the bar menu.
* Return value: 0 returned to parent process.
*--------------------------------------------------------------*/
main()
{
int ret;
int (*funptr)();
char ms_flag;
/* Try to set video mode to EGA
*/
if( mpsetvideomode( _ERESCOLOR ) )
mi_videomode[2].checkmark = 1; /* check off EGA mode in menu */
else if( mpsetvideomode( _HRESBW ) )
mi_videomode[1].checkmark = 1; /* check of HRES in menu */
else
{
printf("\nUnrecognized video hardware.\n");
exit(1);
}
/* Open menu bar with colors defined in menu_info.
*/
mb_open( 1, 1, 80, &menu_info, menubar );
ms_flag = ms_reset();
ms_setevent(1);
ms_showcursor();
if( ms_flag == 0 )
{
gdialog( GDINFORM, GDOKAY );
gdwrite( "No mouse detected but keyboard is\n" );
gdwrite( "supported. Press \"O\" to quit dialogue\n");
gdwrite( "box, then press ALT+first letter of\n");
gdwrite( "menu title. See chapter 6.\n");
gdprompt();
gdclose();
}
funptr = NULL;
while( funptr != exitfun || ret != 0)
{
funptr = mb_run();
if ( funptr != NULL)
ret = funptr(); /* execute selected function */
}
mb_close();
ms_setevent(0);
mpsetvideomode( _DEFAULTMODE );
return 0;
}
/*--------------------------------------------------------------
* Function: dummy
* Description: Dummy function to invoke from bar menu
* Return value: 0
*--------------------------------------------------------------*/
int dummy()
{
gdialog( GDINFORM, GDOKAY );
gdwrite("Function not available.");
gdprompt();
gdclose();
return 0;
}
/*--------------------------------------------------------------
* Function: exitfun
* Description: quit this program
* Return value: 0
*--------------------------------------------------------------*/
int exitfun()
{
int i;
gdialog( GDWARN, GDYESNO );
gdwrite( "Quit bar menu demo?");
i = gdprompt();
gdclose();
return i;
}
/*--------------------------------------------------------------
* Function: memfun
* Description: Display memory info to dialog box
* Return value: 0
*--------------------------------------------------------------*/
int memfun()
{
char buffer[41];
gdialog( GDINFORM, GDOKAY );
sprintf( buffer, "Memory available: %u bytes\n", _memavl() );
gdwrite( buffer );
sprintf( buffer, "Max contiguous block: %u bytes\n", _memmax() );
gdwrite( buffer );
gdprompt();
gdclose();
return 0;
}
/*--------------------------------------------------------------
* Function: mres
* Description: Set the screen to medium resolution, 4 color
* Return value: 0
*--------------------------------------------------------------*/
int mres()
{
char buffer[41];
int i;
gdialog( GDINFORM, GDOKCAN );
gdwrite( "Reset mode to four color,\nmedium resolution?" );
i = gdprompt();
gdclose();
if( i == 0 )
{
mb_close();
if( mpsetvideomode( _MRES4COLOR ) == 0 )
{
gdialog( GDERROR, GDOKAY );
gdwrite( "Video mode not supported by hardware." );
gdprompt();
gdclose();
}
else
{
/* Select colors for palette 1
*/
_selectpalette(1);
menu_info.fg0 = 0x01; /* cyan */
menu_info.bg0 = 0x02; /* magenta */
menu_info.keycolor0 = 0x03; /* light grey */
menu_info.fg = 0x01; /* cyan */
menu_info.bg = 0x03; /* light grey */
menu_info.keycolor = 0x01;
menu_info.greyout0 = menu_info.greyout = 0x03;
/* all checkmarks off. Check off first title in menu.
*/
mb_setbits( mi_videomode, MB_CHECKMARK, 0 );
mi_videomode[0].checkmark = 1;
mb_open( 1, 1, 80, &menu_info, menubar );
ms_showcursor();
}
}
return 0;
}
/*--------------------------------------------------------------
* Function: hres
* Description: Set the screen to black and white hi res
* Return value: 0
*--------------------------------------------------------------*/
int hres()
{
char buffer[41];
int i;
gdialog( GDINFORM, GDOKCAN );
gdwrite( "Reset mode to black and white,\nhigh resolution?" );
i = gdprompt();
gdclose();
if( i == 0 )
{
mb_close();
if( mpsetvideomode( _HRESBW ) == 0 )
{
gdialog( GDERROR, GDOKAY );
gdwrite( "Video mode not supported by hardware." );
gdprompt();
gdclose();
}
else
{
/* Reset colors to black and white.
*/
menu_info.fg0 = menu_info.fg = 0x00;
menu_info.bg0 = menu_info.bg = 0x07;
menu_info.keycolor0 = menu_info.keycolor = 0x07;
menu_info.greyout0 = menu_info.greyout = 0x07;
/* all checkmarks off. Check off second title in menu.
*/
mb_setbits( mi_videomode, MB_CHECKMARK, 0 );
mi_videomode[1].checkmark = 1;
mb_open (1,1,80,